package com.pioneer.web.archive.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pioneer.web.archive.domain.ArcInventory;
import com.pioneer.web.archive.mapper.ArcInventoryMapper;
import com.pioneer.web.archive.service.IArcInventoryService;
import org.springframework.stereotype.Service;

/**
 * ArcInventoryServiceImpl
 *
 * @author hlm
 * @date 2025-03-18 09:20:52
 */
@Service
public class ArcInventoryServiceImpl extends ServiceImpl<ArcInventoryMapper, ArcInventory> implements IArcInventoryService {

    @Override
    public boolean checkCodeUnique(ArcInventory inventory) {
        // 新增：select count(*) from arc_inventory where inventory_code = #{inventoryCode}
        LambdaQueryWrapper<ArcInventory> query = Wrappers.lambdaQuery();
        query.eq(ArcInventory::getInventoryCode, inventory.getInventoryCode());
        // 修改：select count(*) from arc_inventory where inventory_code = #{inventoryCode} and inventory_id <> #{inventoryId}
        if (inventory.getInventoryId() != null) {
            query.ne(ArcInventory::getInventoryId, inventory.getInventoryId());
        }
        return getBaseMapper().exists(query);
    }
}
